<#include "include/_meta.html">
<title>年检记录列表</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 车辆管理<span class="c-gray en">&gt;</span> 车辆保养记录 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
	<div class="text-c">
		<input type="text" class="input-text" style="width:250px" placeholder="车牌号" id="likecarid" name="">
		 开始时间：
		<input type="text" onfocus="WdatePicker({maxDate:'#F{$dp.$D(\'datemax\')||\'%y-%M-%d\'}'})" id="datemin" class="input-text Wdate" style="width:120px;">
		截止时间：
		<input type="text" onfocus="WdatePicker({minDate:'#F{$dp.$D(\'datemin\')}',maxDate:'%y-%M-%d'})" id="datemax" class="input-text Wdate" style="width:120px;">
		
		<button type="submit" class="btn btn-success" id="searchYearCheck" name=""><i class="Hui-iconfont">&#xe665;</i> 搜索</button>
	</div>
	<div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l"><a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a> <a href="javascript:;" onclick="yearcheck_add('添加年检记录','yearcheck-add.html','800','500')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加年检记录</a></span> <span class="r">共有数据：<strong id="pageTotal">54</strong> 条</span> </div>
	<table id="yearchackTable" class="table table-border table-bordered table-bg table-hover">
		<thead>
			<tr>
				<th scope="col" colspan="9">年检列表</th>
			</tr>
			<tr class="text-c">
				<th width="25"><input type="checkbox" name="yearcheckitem" value=""></th>
				<!--<th width="40">ID</th>-->
				<th width="150">年检车辆</th>
				<th width="150">年检地点</th>
				<th width="150">外出时间</th>
				<th width="150">归还时间</th>
				<th width="130">年检费用</th>
				<th width="100">经手人</th>
				<th width="100">操作</th>
			</tr>
		</thead>
		<tbody>

		</tbody>
	</table>
</div>

<#include "include/_footer.html">

<script type="text/javascript">

$(function(){

    initTable();
  
});


var initTable = function(){

$('#yearchackTable').dataTable( {
    
		"processing": false,
      	"serverSide": true,
      	"bSort": false,
      	"bFilter":false,
      	"bLengthChange":false,
      	"iDisplayLength":10,
      	"bRetrieve":true,
      	"ajax": {
            "url": '/yearCheck',
				
           	"data":function(d){
					
		        d.carid = $('#likecarid').val();
		        d.datemin = $('#datemin').val();
		        d.datemax = $('#datemax').val();

		    },

            "type": "get"

        },
        "columns": [
            { "data": "" },
            //{ "data": "recordid" },
            { "data": "carid" },
            { "data": "address" },
            { "data": "usecartime" },
            { "data": "returntime" },
            { "data": "costmoney" },
            { "data": "headman" },			
            { "data": "" }
      	],
      	"columnDefs": [
	        {
		          "targets": [0],
		          "data": "recordid",
		          "render": function(data, type, full) {
		            return "<input type='checkbox' value=" + full.recordid + " name='yearcheckitem'>";
		            //return full.recordid+"";
		          }
	        },
	        {
		          "targets": [7],
		          "data": "recordid",
		          "render": function(data, type, full) {
		          
		          			var action_isabled = "<a style='text-decoration:none' onClick=\"yearcheck_start(this,'"+full.recordid+"')\" href=\"javascript:;\" title=\"启用\"><i class=\"Hui-iconfont\">&#xe615;</i></a>";
		          			if(full.isabled == '1'){
		          				action_isabled = "<a style='text-decoration:none' onClick=\"yearcheck_stop(this,'"+full.recordid+"')\" href=\"javascript:;\" title=\"停用\"><i class=\"Hui-iconfont\">&#xe631;</i></a>";
		          			}
		          			var action_edit    = "<a title=\"编辑\" href=\"javascript:;\" onclick=\"yearcheck_edit('年检记录编辑','/yearcheck-edit?recordid="+full.recordid+"','2','800','500')\" class=\"ml-5\" style=\"text-decoration:none\"><i class=\"Hui-iconfont\">&#xe6df;</i></a>";
		          			var action_del     = "<a title=\"删除\" href=\"javascript:;\" onclick=\"yearcheck_del(this,'"+full.recordid+"')\" class=\"ml-5\" style=\"text-decoration:none\"><i class=\"Hui-iconfont\">&#xe6e2;</i></a>";
		          
		            		return action_isabled+" "+action_edit+" "+action_del;
		          }
	        }	        
      	],
      	"fnRowCallback" : function(nRow, aData, iDisplayIndex) { 
      					nRow.className="text-c";       
      					if (aData.isabled == '1') {
                            $('td:eq(6)', nRow).html("<span class=\"label label-success radius\">已启用</span>");  
                        }  
                        if (aData.isabled == '0') {
                            $('td:eq(6)', nRow).html("<span class=\"label radius\">已停用</span>");    
                        } 
                        $('td:eq(6)', nRow).addClass("td-status");  
                        $('td:eq(7)', nRow).addClass("td-manage");                     
                        return nRow;  
         },
	    "fnDrawCallback": function(oSettings) {
		      //获取后台方式 直接可以拿到json 之后进行处理
		      var json=jQuery.parseJSON(oSettings.jqXHR.responseText);  
		      $("#pageTotal").html(json.recordsTotal);
	    }
  
      	
    });

}


$("#searchYearCheck").click(function() {
    	var i_data = $('#likecarid').val();
    	console.log("datemin:"+ $('#datemin').val());
    	console.log("datemax:"+ $('#datemax').val());

        $("#yearchackTable").dataTable().fnClearTable();
        initTable();
});



var datadel = function(){
	
	//判断选择项是否为空
	var checkedNum = $("input[name='yearcheckitem']:checked").length;
	if(checkedNum==0){
		layer.msg('请选中要删除的列表项!',{icon: 5,time:1000});
		return;
	}
	//获取选择项的值
	var checkedVal = "";
	$("input[name='yearcheckitem']:checked").each(function(){  
		checkedVal+=$(this).val()+",";  
	});
	
	var itemsTipStr = "这条记录";
	if(checkedNum>1){
		itemsTipStr = "这些选项";
	}
	
	layer.confirm('确认要删除'+itemsTipStr+'吗？',function(){
	
		//此处请求后台程序，下方是成功后的前台处理……
		$.ajax({
		   type: "POST",
		   url: "/delYearChecks",
		   data: "recordid="+checkedVal,
		   success: function(msg){
		   		   
				layer.msg('已删除!',{icon: 5,time:1000});
				
				$("#yearchackTable").dataTable().fnClearTable();
		        initTable();
		   }
		});
		

        
	});
	
	
}


/*
	参数解释：
	title	标题
	url		请求的url
	id		需要操作的数据recordid
	w		弹出层宽度（缺省调默认值）
	h		弹出层高度（缺省调默认值）
*/
/*年检记录-增加*/
function yearcheck_add(title,url,w,h){
	layer_show(title,url,w,h);
}
/*年检记录-删除*/
function yearcheck_del(obj,recordid){
	layer.confirm('确认要删除吗？',function(index){
		//此处请求后台程序，下方是成功后的前台处理……
		
		
		$.ajax({
		   type: "POST",
		   url: "/delYearCheck",
		   data: "recordid="+recordid,
		   success: function(msg){
		       	$("#yearCheckTable").dataTable().fnClearTable();
        		initTable();
		   }
		});
		
		
		$(obj).parents("tr").remove();
		layer.msg('已删除!',{icon:1,time:1000});
	});
}



/*年检记录-编辑*/
function yearcheck_edit(title,url,id,w,h){
	layer_show(title,url,w,h);
}
/*年检记录-停用*/
function yearcheck_stop(obj,id){
	layer.confirm('确认要停用吗？',function(index){
		//此处请求后台程序，下方是成功后的前台处理……
		
		$.ajax({
		   type: "POST",
		   url: "/setUserState",
		   data: "reocordid="+id+"&isabled=0",
		   success: function(msg){
		       	$("#userListTable").dataTable().fnClearTable();
        		initTable();
		   }
		});
		
		$(obj).parents("tr").find(".td-manage").prepend('<a onClick="yearcheck_start(this,id)" href="javascript:;" title="启用" style="text-decoration:none"><i class="Hui-iconfont">&#xe615;</i></a>');
		$(obj).parents("tr").find(".td-status").html('<span class="label label-default radius">已禁用</span>');
		$(obj).remove();
		layer.msg('已停用!',{icon: 5,time:1000});
	});
}

/*年检记录-启用*/
function yearcheck_start(obj,id){
	layer.confirm('确认要启用吗？',function(index){
			
		
		$.ajax({
		   type: "POST",
		   url: "/setUserState",
		   data: "recordid="+id+"&isabled=1",
		   success: function(msg){
		       	$("#userListTable").dataTable().fnClearTable();
        		initTable();
		   }
		});
		
		
		//$(obj).parents("tr").find(".td-manage").prepend('<a onClick="admin_stop(this,id)" href="javascript:;" title="停用" style="text-decoration:none"><i class="Hui-iconfont">&#xe631;</i></a>');
		//$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已启用</span>');
		//$(obj).remove();
		layer.msg('已启用!', {icon: 6,time:1000});
	});
}
</script>
</body>
</html>